package getCourseMapping;

import java.io.File;
import java.io.FileOutputStream;

import com.alibaba.fastjson.JSONObject;

public class MyThread extends Thread implements Runnable {

	@Override
	public void run() {
		// TODO 自动生成的方法存根
		Integer startIdInteger = Integer.parseInt(Thread.currentThread().getName());
		System.err.println(Thread.currentThread().getName() + "-process: 0");
		for(int i = startIdInteger;i< startIdInteger + 1000 ;i++) {
			if(i%100==0) System.err.println(Thread.currentThread().getName() + "-process: " + i);
			String result = GetCourseList.getInfo(i);
			JSONObject jObject = JSONObject.parseObject(result);
			String cName = jObject.getJSONObject("data").getString("name");
			if(cName!=null) {
				if(cName.contains("试用")) continue;
				//System.err.println(cName);
				GetCourseList.courseMapping.put(i, cName);
			}
		}
		
		try {
			FileOutputStream fOut = new FileOutputStream(new File("courseMap.txt"));
			
			fOut.write(GetCourseList.courseMapping.toString().getBytes());
			
			fOut.close();
		}catch (Exception e) {
			// TODO: handle exception
		}
		
		System.err.printf("线程%s 操作完毕\n",Thread.currentThread(),getName());
	}

}
